<%--
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
--%>
<%@ include file="/taglibs.jsp" %>
<c:set var="title" value="${type} a Story" scope="request"/>
<s:layout-render name="/layout/normal.jsp">
  <s:layout-component name="body">
  [
  <c:choose>
    <c:when test="${xp:isFit(actionBean.story.descriptionContent)}">
      <xp:wiki-preview id="storyDescription" display="Preview Description (Markdown)"/>
      <xp:wiki-preview id="storyDescription" display="Preview Description (FitNesse)" style="fitnesse"/>
    </c:when>
    <c:otherwise>
      <xp:wiki-preview id="storyDescription" display="Preview Description"/>
    </c:otherwise>
  </c:choose>
    ]
    <s:form name="story" beanclass="org.xptracker.web.StoryActionBean">
      <s:hidden name="story.id"/>
      <s:hidden name="story.extId"/>
      <table class="form">
        <tr>
          <td class="form-label"><span style="color:red">*</span> Summary:</td>
          <td colspan="3"><s:text id="summary" name="story.summary" size="80"/></td>
        </tr>
        <tr>
          <td class="form-label">Severity:</td>
          <td colspan="3">
            <span class="radio-block cold">
              <s:radio id="sev_cold" value="cold" name="story.severity"/><label for="sev_cold" class=""> Cold</label>
            </span>

            <span class="radio-block tepid">
              <s:radio id="sev_tepid" value="tepid" name="story.severity"/><label for="sev_tepid" class=""> Tepid</label>
            </span>

            <span class="radio-block warm">
              <s:radio id="sev_warm" value="warm" name="story.severity"/><label for="sev_warm" class=""> Warm</label>
            </span>

            <span class="radio-block hot">
              <s:radio id="sev_hot" value="hot" name="story.severity"/><label for="sev_hot" class=""> Hot</label>
            </span>

            <span class="radio-block scorcher">
              <s:radio id="sev_scorcher" value="scorcher" name="story.severity"/><label for="sev_scorcher" class=""> Scorcher</label>
            </span>
          </td>
        </tr>
        <tr>
          <td class="form-label">Size:</td>
          <td colspan="3">
            <span class="radio-block">
              <s:radio id="size_petit" value="petit" name="story.size"/><label for="size_petit" style="font-size:0.75em"> Petit</label>
            </span>

            <span class="radio-block">
              <s:radio id="size_small" value="small" name="story.size"/><label for="size_small" style="font-size:0.9em"> Small</label>
            </span>

            <span class="radio-block">
              <s:radio id="size_medium" value="medium" name="story.size"/><label for="size_medium"> Medium</label>
            </span>

            <span class="radio-block">
              <s:radio id="size_large" value="large" name="story.size"/><label for="size_large" style="font-size:1.2em"> Large</label>
            </span>

            <span class="radio-block">
              <s:radio id="size_xl" value="xl" name="story.size"/><label for="size_xl" style="font-size:1.35em"> XL</label>
            </span>
          </td>
        </tr>
        <tr>
          <td class="form-label">Due:</td>
          <td><s:text name="story.dueDate"/></td>
          <td class="form-label">Estimate:</td>
          <td style="width:40%"><s:text name="story.estimate"/> hours
            (effort: <fmt:formatNumber value="${xp:fromMillis(actionBean.story.totalEffort, 'hours')}" pattern="##.#"/>)
          </td>
        </tr>
        <c:set var="newStory" value="${empty actionBean.story.id}"/>
        <c:if test="${newStory && !empty actionBean.openQueues}">
          <tr>
            <td class="form-label">Queue:</td>
            <td colspan="3">
              <s:select name="queueId">
                <s:option value="">None</s:option>
                <s:options-collection collection="${actionBean.openQueues}" value="id" label="name"/>
              </s:select>
            </td>
          </tr>
        </c:if>
        <tr>
          <td class="form-label">Description:<br/>(<a href="http://daringfireball.net/projects/markdown/dingus" target="_blank">Help</a>)</td>
          <td colspan="3"><s:textarea id="storyDescription" name="story.description" rows="15" cols="80"/></td>
        </tr>
        <c:if test="${xp:isFit(actionBean.story.descriptionContent)}">
          <tr>
            <td>Description Style:</td>
            <td>
              <span class="radio-block">
                <s:radio id="fitS" name="story.descriptionContent.wikiStyle" value="markdown"/><label for="fitS">MarkDown</label>
              </span>
              <span class="radio-block">
                <s:radio id="mdS" name="story.descriptionContent.wikiStyle" value="fitnesse"/>
                <label for="mdS" style="font-weight:normal;">FitNesse</label>
              </span>
            </td>
          </tr>
        </c:if>
        <c:if test="${newStory}">
          <tr>
            <td class="form-label">Categories:</td>
            <td colspan="3">
              <c:choose>
                <c:when test="${!empty actionBean.availableCategories}">
                  <span id="categories_toggle">
                    <a href="#" onclick="toggleCategories()">Add...</a>
                  </span>
                  <div id="categories_editor" style="display:none">
                   <c:set var="catCount" value="0"/>
                   <c:forEach var="entry" items="${actionBean.availableCategories}">
                    <fieldset class="category-box">
                      <legend>${empty entry.key ? 'Default' : entry.key}</legend>
                        <table style="width:100%">
                       <c:forEach var="category" begin="0" end="${xp:size(entry.value) - 1}" step="3" varStatus="stat">
                          <tr>
                            <c:forEach begin="0" end="2" varStatus="substat">
                              <c:set var="catIdx" value="${stat.index + substat.index}"/>
                              <c:set var="category" value="${entry.value[catIdx]}"/>
                              <td style="width:33%">
                                <c:if test="${!empty category}">
                                  <span class="checkbox-block">
                                    <input type="checkbox" name="categories" id="cat_${catCount}" value="${category.name}"/>
                                    <label style="font-weight:normal" for="cat_${catCount}">${category.name}</label>
                                  </span>
                                </c:if>
                              </td>
                              <c:set var="catCount" value="${catCount + 1}"/>
                            </c:forEach>
                          </tr>
                        </c:forEach>
                        </table>
                      </fieldset>
                  </c:forEach>
                    <a href="#" onclick="toggleCategories()">Hide...</a>
                  </div>
                </c:when>
                <c:otherwise><em>No categories available.</em></c:otherwise>
              </c:choose>
            </td>
          </tr>
          <tr>
            <td class="form-label">Customers:</td>
            <td colspan="3">
              <c:choose>
                <c:when test="${!empty actionBean.availableCustomers}">
                  <span id="customers_toggle">
                    <a href="#" onclick="toggleCustomers()">Add...</a>
                  </span>
                  <table id="customers_editor" style="display:none">
                  <c:forEach var="customer" begin="0" end="${xp:size(actionBean.availableCustomers) - 1}" step="3" varStatus="stat">
                    <tr>
                      <c:forEach begin="0" end="2" varStatus="substat">
                        <c:set var="custIdx" value="${stat.index + substat.index}"/>
                        <c:set var="customer" value="${actionBean.availableCustomers[custIdx]}"/>
                        <td>
                          <c:if test="${!empty customer}">
                            <span class="checkbox-block">
                              <input type="checkbox" name="customerIds" id="cst_${custIdx}" value="${customer.id}"/>
                              <label style="font-weight:normal" for="cst_${custIdx}">${customer.name}</label>
                            </span>
                          </c:if>
                        </td>
                      </c:forEach>
                    </tr>
                  </c:forEach>
                    <tr><td colspan="3">
                      <a href="#" onclick="toggleCustomers();">Hide...</a>
                    </td></tr>
                  </table>
                </c:when>
                <c:otherwise><em>No customers available.</em></c:otherwise>
              </c:choose>
            </td>
          </tr>
          <tr>
            <td class="form-label">Trackers:</td>
            <td colspan="3">
              <c:choose>
                <c:when test="${!empty actionBean.availableTrackers}">
                  <span id="trackers_toggle">
                    <a href="#" onclick="toggleTrackers()">Add...</a>
                  </span>
                  <table id="trackers_editor" style="display:none">
                  <c:forEach var="tracker" begin="0" end="${xp:size(actionBean.availableTrackers) - 1}" step="3" varStatus="stat">
                    <tr>
                      <c:forEach begin="0" end="2" varStatus="substat">
                        <c:set var="trackIdx" value="${stat.index + substat.index}"/>
                        <c:set var="tracker" value="${actionBean.availableTrackers[trackIdx]}"/>
                        <td>
                          <c:if test="${!empty tracker}">
                            <span class="checkbox-block">
                              <input type="checkbox" name="trackerUsernames" id="trk_${trackIdx}" value="${tracker.username}"/>
                              <label style="font-weight:normal" for="trk_${trackIdx}">${tracker.username}</label>
                            </span>
                          </c:if>
                        </td>
                      </c:forEach>
                    </tr>
                  </c:forEach>
                    <tr><td colspan="3">
                      <a href="#" onclick="toggleTrackers();">Hide...</a>
                    </td></tr>
                  </table>
                </c:when>
                <c:otherwise><em>No trackers available.</em></c:otherwise>
              </c:choose>
            </td>
          </tr>
        </c:if>
        <tr>
          <td/><td colspan="3"><s:submit name="${type}" value="${type}"/></td>
        </tr>
      </table>
    </s:form>
    <script type="text/javascript">
      $('summary').focus();

      function toggleCategories() {
        Element.toggle('categories_toggle');
        Element.toggle('categories_editor');
      }
      function toggleCustomers() {
        Element.toggle('customers_toggle');
        Element.toggle('customers_editor');
      }
      function toggleTrackers() {
        Element.toggle('trackers_toggle');
        Element.toggle('trackers_editor');
      }
    </script>

  <span style="font-size:0.8em; font-weight:lighter;"><span style="color:red">*</span> = required field</span>
  </s:layout-component>
</s:layout-render>